The base or simple types of Free Pascal are the Delphi types. We will discuss each separate.
Simple types
With the exception of Real types, all base types are ordinal types.
Ordinal types have the following characteristics:
A list of pre-defined ordinal types is presented in table ()
Name |
Integer |
Shortint |
SmallInt |
Longint |
Byte |
Word |
Cardinal |
Boolean |
ByteBool |
LongBool |
Char |
The integer types, and their ranges and sizes, that are predefined in
Free Pascal are listed in table ().
Free Pascal does automatic type conversion in expressions where different kinds of integer types are used.
Free Pascal supports the Boolean type, with its two pre-defined possible values True and False, as well as the ByteBool, WordBool and LongBool. These are the only two values that can be assigned to a Boolean type. Of course, any expression that resolves to a boolean value, can also be assigned to a boolean type.
Name | Size | Ord(True) |
Boolean | 1 | 1 |
ByteBool | 1 | Any nonzero value |
WordBool | 2 | Any nonzero value |
LongBool | 4 | Any nonzero value |
Assuming B to be of type Boolean, the following are valid
assignments:
Boolean expressions are also used in conditions.
Remark: In Free Pascal, boolean expressions are always evaluated in such a
way that when the result is known, the rest of the expression will no longer
be evaluated (Called short-cut evaluation). In the following example, the function Func will never
be called, which may have strange side-effects.
Here Func is a function which returns a Boolean type.
Remark: The wordbool, longbool and bytebool were not supported by Free Pascal until version 0.99.6.
Enumeration types are supported in Free Pascal. On top of the Turbo Pascal implementation, Free Pascal allows also a C-style extension of the enumeration type, where a value is assigned to a particular element of the enumeration list.
Enumerated types
(see chapter () for how to use expressions)
When using assigned enumerated types, the assigned elements must be in
ascending numerical order in the list, or the compiler will complain.
The expressions used in assigned enumerated elements must be known at compile time.
So the following is a correct enumerated type declaration:
The C style enumeration type looks as follows:
As a result, the ordinal number of forty is 40, and not 3,
as it would be when the ':= 40' wasn't present.
When specifying such an enumeration type, it is important to keep in mind that you should keep initialized set elements in ascending order. The following will produce a compiler error:
It is necessary to keep forty and thirty in the correct order.
When using enumeration types it is important to keep the following points in mind:
Small enum : 1 Large enum : 4
A subrange type is a range of values from an ordinal type (the host type). To define a subrange type, one must specify it's limiting values: the highest and lowest value of the type.
Subrange types
Some of the predefined integer types are defined as subrange types:
But you can also define subrange types of enumeration types:
Free Pascal uses the math coprocessor (or an emulation) for all its floating-point
calculations. The Real native type is processor dependant,
but it is either Single or Double. Only the IEEE floating point types are
supported, and these depend on the target processor and emulation options.
The true Turbo Pascal compatible types are listed in
table ().
Until version 0.9.1 of the compiler, all the Real types are mapped to type Double, meaning that they all have size 8. The SizeOf function is your friend here. The Real type of turbo pascal is automatically mapped to Double. The Comp type is, in effect, a 64-bit integer.